💯 solving-algo | March 10, 2021
https://leetcode.com/problems/valid-parentheses/
def isValid(s):
stack = []
table = {
')' : '(',
'}' : '{',
']' : '[',
}
# 스택 이용 예외 처리 및 일치 여부 판별
for char in s:
if char not in table:
stack.append(char)
elif not stack or table[char] != stack.pop():
return False
return len(stack) == 0
print(isValid('()[]{}'))
table를 정의해놓고 매핑해 해당 테이블과 매핑이 안되는 스택은 False, 나머진 True을 이용해 풀이